from django.shortcuts import render

from rest_framework.generics import ListAPIView
from .models import Banner
from .serializers import BannerModelSerializer  #序列化器
from luffyapi.settings import constants
class BannerListAPIView(ListAPIView): # 自动导包
    """
        获取多条数据，因为这个接口不会通过前端修改，删除都不需要，只是查询，满足这个所以使用列表查询 ListAPIView
    """
    """
        .order_by("-orders","-id")
            order_by排序，如果是倒序用"-orders"，正序用"orders"
            "-id" id值越大越靠前
        [:constants.BANNER_LENGTH] 对查询的数据切片，类似[:10]
    """
    queryset = Banner.objects.filter(is_show=True, is_deleted=False).order_by("-orders","-id")[:constants.BANNER_LENGTH]
    #使用序列化器
    serializer_class = BannerModelSerializer

from .models import Nav
from .serializers import NavModelSerializer
class HeaderNavListAPIView(ListAPIView):
    """导航菜单视图"""
    queryset = Nav.objects.filter(is_show=True, is_deleted=False,position=1).order_by("-orders","-id")[:constants.HEADER_NAV_LENGTH]
    serializer_class = NavModelSerializer

class FooterNavListAPIView(ListAPIView):
    """脚部菜单视图"""
    queryset = Nav.objects.filter(is_show=True, is_deleted=False,position=2).order_by("-orders","-id")[:constants.FOOTER_NAV_LENGTH]
    serializer_class = NavModelSerializer










